package com.ruoyi.web.controller.wlsggk;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.waterdrop.wlsggk.pojo.MaterialBuy;
import com.waterdrop.wlsggk.service.MaterialBuyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/wlsggk/MaterialBuy")
public class MaterialBuyController extends BaseController {
    @Autowired
    private MaterialBuyService materialBuyService;

    /**
     * 获取物料列表
     */
    @GetMapping("/list")
    public TableDataInfo list(MaterialBuy materialBuy) {
        startPage();
        List<MaterialBuy> list = materialBuyService.selectMaterialBuyList(materialBuy);
        return getDataTable(list);
    }

    /**
     * 删除物料信息
     */
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(materialBuyService.deleteWlsggkMaterialBuy(ids));
    }

    /**
     * 根据物料id查询
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable Long id) {
        return success(materialBuyService.selectWlsggkMaterialBuyById(id));
    }

    /**
     * 新增物料
     */
    @PostMapping
    public AjaxResult add(@Validated @RequestBody List<MaterialBuy> materialBuy) {
        return toAjax(materialBuyService.insertWlsggkMaterialBuy(materialBuy));
    }

    /**
     * 修改物料信息
     */
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody MaterialBuy materialBuy) {
        return toAjax(materialBuyService.updateWlsggkMaterialBuy(materialBuy));
    }


}
